<?php
/**
 * Created by PhpStorm.
 * User: yangyou
 * Date: 2019/1/3 0003
 * Time: 15:39
 */

namespace app\index\model;


class UserCookie extends Base
{
    /**
     * Author:yang you
     * Time:2018-12-2 10:27:51
     * Describe:用户浏览记录列表
     * @return int|string
     */
    public function browseList($user_id,$field ="",$after_limit = "8"){
        $keyInfo = $this->alias('a')->field('a.key')->where("user_id",$user_id)->select();
        $browse_log = $this->table('shop_browserecord')->alias('c')->field('c.*,b.no,b.topic,b.price,b.cover,b.create_time')
            ->where(function ($query)use ($field){
                if(!empty($field)) {
                    $query->where('c.'.$field,"neq",0);
                }
            })
            ->where(function ($query)use ($keyInfo){
                if(!empty($keyInfo)) {
                    foreach ($keyInfo as $v){
                        $query->whereor("key", $v["key"]);
                    }
                }
            })
            ->join('shop_drawing b','c.drawing_id = b.drawing_id','left')
            ->orderRaw("access_time desc")
            ->paginate($after_limit,false,[
                'type'     => 'page\marketPage',
                'var_page'  => 'p',
                'query' =>  request()->param(),
            ]);
        return $browse_log;
    }

    //验证cookie是否存在
    public function cookieName($cookie_key){
        return $this->where("key",$cookie_key)->find();
    }

}